﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConferenceArranger.BusinessRules;

namespace ConferenceArranger.ConferenceComponent
{   
    /// <summary>
    /// A session has a list of talk and one break event (lunch or networking)
    /// date of session is the date of its track
    /// </summary>
    class Session
    {   
        // type can be either morning or afternoon
        private string type;
        //interval can be 180 or 240 mins depending on its type
        private int interval;
        private List<Talk> talkList;
        private Break eventBreak;
        private DateTime sessionDate;

        public Session(string type)
        {
            this.type = type;
            this.interval = SessionHelper.GetSessionInterval(this.type);
        }

        public int GetInterval()
        {
            return interval;
        }

        public string GetType()
        {
            return type;
        }

        public void SetTalkList(List<Talk> talkList)
        {
            this.talkList = talkList;
        }

        /// <summary>
        /// After choosing all the talks, assign time to each of them. Then assign time to break
        /// logic is from SessionHelper class
        /// </summary>
        public void SetStartTimeForEvent()
        {
            this.talkList = SessionHelper.SetStartTimeForEvent(talkList, this.type, this.sessionDate);
            //calculate the end time of last talk of a session
            DateTime lastEventEndTime = 
                talkList[talkList.Count-1].GetStartTime().AddMinutes(talkList[talkList.Count-1].GetInterval());

            Break sessionBreak = SessionHelper.SetBreak(lastEventEndTime, this.type);
            SetBreak(sessionBreak);
        }

        public void SetBreak(Break bre)
        {
            this.eventBreak = bre;
        }


        public void SetDateTime(DateTime date)
        {
            this.sessionDate = date;
        }

        public DateTime GetDateTime()
        {
            return this.sessionDate;
        }


        public string ToString()
        {
            string myString = "";
            for (int i = 0; i < talkList.Count; i++)
            {
                myString += talkList[i].ToString() + "\r\n";
            }

            myString += eventBreak.ToString();

            return myString;
        }

    }
}
